import type { SchemaNodeType, ChunkConfig } from './schema';
export interface Package {
  /**
   * 组件导出名称
   */
  exportName?: string;
  /**
   * 子组件名称
   */
  subName?: string[];
  /**
   * 组件库名称，
   */
  packageName: string;
  /**
   * 是否结构
   */
  destructuring?: boolean;
  /**
   * 版本号
   */
  version?: string;
}
export interface SourceCode {
  /**
   * 源码组件名称
   */
  componentName: string;
  /**
   * 是否导出
   */
  export?: boolean;
  /**
   * 组件属性
   */
  props?: string[];
  /**
   * 子元素
   */
  children?: string | ChildType[];
  /**
   * 默认导出的组件名称
   */
  defaultExportName?: boolean;
  /**
   * 导入的资源列表，渲染模板时使用
   */
  imports: string[];
  /**
   * 组件状态
   */
  state?: Record<string, any>;
  /**
   * 自定义方法
   */
  methods?: string[];
  /**
   * 生命周期
   */
  lifeCycles?: string[];
}

export interface NodeGeneratorProps {
  schema: SchemaNodeType;
}
export interface INodeGenerator {
  readonly schema: SchemaNodeType;
  readonly packagesParser: PackagesParserProps;
  readonly methodsParser: MethodsParserProps;
  readonly lifeCyclesParser: LifeCyclesParserProps;
  readonly stateParser: StateParserProps;
  readonly propsParser: PropsParserProps;
  readonly childrenParser: ChildrenParserProps;
  compiler: () => Promise<SourceCode>;
}
export interface PageGeneratorProps extends NodeGeneratorProps {}
export interface IPageGenerator extends INodeGenerator {}
export interface ConfigType {
  schemaFilePath: string;
}

interface ChildType extends SourceCode {
  /**
   * 子组件是否拆分为单独的文件中
   */
  chunk?: ChunkConfig;
}
export enum PackagesLevel {
  /**
   * 环境基础包 例如react
   */
  Environment = 1,
  /**
   * 第三方包 例如antd
   */
  Library = 2,
  /**
   * 私有包 例如 公司组件库
   */
  PrivateLibrary = 3,
  /**
   * 本项目内组件、工具 例如 @/component/xx
   */
  Project = 4,
  /**
   * 当前组件的工具 例如 ./xx
   */
  Component = 5,
  /**
   * 样式
   */
  Css = 6,
}
export interface SchemaMetaProps {
  readonly schema: SchemaNodeType;
}
export interface SchemaMetaConstructorProps {
  schema: SchemaNodeType;
}
export interface PackagesParserProps extends SchemaMetaProps {
  toString: () => string[];
  setPackages: (levle: PackagesLevel, packageItem: Package) => void;
  getPackages: () => Package[];
  setEnvironmentPackages: (packageItem: Package) => void;
}
export interface PackagesParserConstructorProps extends SchemaMetaConstructorProps {}

export interface ParserContructorProps extends SchemaMetaConstructorProps {}
export type ParserParseParams = {
  schemaName: 'methods' | 'lifeCycles';
};
export interface ParserProps extends SchemaMetaProps {}
export interface MethodsParserContructorProps extends ParserContructorProps {}
export interface MethodsParserProps extends ParserProps {
  parse: () => Promise<SourceCode['methods']>;
}

export interface LifeCyclesParserContructorProps extends ParserContructorProps {
  packagesParser: PackagesParserProps;
}
export interface LifeCyclesParserProps extends ParserProps {
  parse: () => Promise<SourceCode['lifeCycles']>;
}

export interface StateParserProps extends SchemaMetaProps {
  parse: () => Promise<SourceCode['state']>;
}
export interface StateParserConstructorProps extends SchemaMetaConstructorProps {
  packagesParser: PackagesParserProps;
}

export interface PropsParserProps extends SchemaMetaProps {
  parse: () => Promise<SourceCode['props']>;
}
export interface PropsParserConstructorProps extends SchemaMetaConstructorProps {}

export interface ChildrenParserConstructorProps extends SchemaMetaConstructorProps {}
export interface ChildrenParserProps extends SchemaMetaProps {
  parse: () => Promise<SourceCode['children']>;
}
